package com.lzy.util;

import java.util.Date;
import java.text.ParseException;
import java.text.SimpleDateFormat;


public class DateUtil {
	
	public final static String DATEFORMAT1 = "yyyy-MM-dd HH:mm:ss";
	
	public final static String DATEFORMAT2 = "yyyy-MM-dd HH:mm";
	
	public static String date2String(Date date){
		SimpleDateFormat dateFormat = new SimpleDateFormat(DATEFORMAT1);
		return dateFormat.format(date);
	}
	
	public static Date string2Date(String date){
		return string2Date(date,DATEFORMAT1);
	}
	
	public static Date string2Date(String date,String format){
		SimpleDateFormat dateFormat = new SimpleDateFormat(format);
		try {
			return dateFormat.parse(date);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
	
	public static Date simpleString2Date(String day,String hour,String minute,String second){
		String strDate= day+" "+hour+":"+minute+":"+second ;
		return string2Date(strDate);
	}
}
